﻿@page "/AddOrder"



@using Microsoft.AspNetCore.Identity
@using BlazorOrdering.Web.Entry.Areas.Identity.Data
@using BlazorOrdering.Core
@using Foo = BlazorOrdering.Core.Order;
@inject BlazorOrdering.Application.IOrderService  orderService



<Card Color="Color.Success">
    <CardHeader>
        本次已点订单
    </CardHeader>
    <CardBody>
        <Table TItem="Foo" Items="@Orders" IsStriped="true">
            <TableColumns>
                <TableColumn @bind-Field="@context.UserName" />
                <TableColumn @bind-Field="@context.Day" FormatString="MM月dd日 dddd" />
                <TableColumn @bind-Field="@context.Total" FormatString="0.00" />
            </TableColumns>
        </Table>
    </CardBody>
    <CardFooter>
        
    </CardFooter>
</Card>

<h3>点餐</h3>

<ValidateForm class="form-inline" Model="@Order" OnValidSubmit="@OnValidSubmit" OnInvalidSubmit="@OnInvalidSubmit">
    <div class="row">
        <div class="form-group col-12 col-sm-12">
            <BootstrapInput @bind-Value="@Order.UserName" IsDisabled="true" />
        </div>

        <div class="form-group col-12  col-sm-12">

            <DateTimePicker TValue="DateTime?"
                            Value="@Order.Day"
                            ValueChanged="@DateValueChanged"
                            Placement="Placement.Right"
                            DisplayText="用餐日期"
                            ShowLabel="true"
                            Format="MM月dd日 dddd" />
        </div>
        <div class="form-group col-12  col-sm-12">
            @foreach (OrderStatement orderStatement in Order.OrderDetails)
            {
                var temporderStatement = orderStatement;
                <OrderStatementCard @bind-orderStatement="@temporderStatement"
                                    boMenus="boMenus"
                                    OnClickCallback="@OrderCalculate"
                                    CloseOneselfClickCallback="@CloseOneOrderStatement"></OrderStatementCard>
            }

            <Card Color="Color.Primary" Class="ml-3  mt-2" style="width: 18rem; min-height:20.5rem">
                <CardHeader>

                </CardHeader>
                <CardBody>

                    <div>

                        <Button IsOutline="true" Color="Color.Primary" IsBlock="true" Icon="fa fa-cart-plus" @onclick="@AddorderStatement">增加</Button>
                    </div>


                </CardBody>
                <CardFooter>

                </CardFooter>
            </Card>

        </div>

        <div class="form-group col-12  col-sm-12">
            <h4> ￥@Order.Total.ToString("0.00")</h4>
        </div>
        <div class="form-group col-12  col-sm-12">
            <Button ButtonType="@ButtonType.Submit" Text="提交订单" />
        </div>
    </div>
</ValidateForm>

<Message @ref="MessageElement" />



@code {

    private void OrderCalculate()
    {
        this.Order.Calculate();
    }

}
